package com.tyut.musicdreamer.service.music.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tyut.musicdreamer.service.music.model.entity.Music;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 音乐Mapper
 */
@Mapper
public interface MusicMapper extends BaseMapper<Music> {

    /**
     * 增加播放次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET play_count = play_count + 1 WHERE id = #{musicId}")
    int incrementPlayCount(@Param("musicId") String musicId);

    /**
     * 增加点赞次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET like_count = like_count + 1 WHERE id = #{musicId}")
    int incrementLikeCount(@Param("musicId") String musicId);

    /**
     * 减少点赞次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET like_count = like_count - 1 WHERE id = #{musicId} AND like_count > 0")
    int decrementLikeCount(@Param("musicId") String musicId);

    /**
     * 增加收藏次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET favorite_count = favorite_count + 1 WHERE id = #{musicId}")
    int incrementFavoriteCount(@Param("musicId") String musicId);

    /**
     * 减少收藏次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET favorite_count = favorite_count - 1 WHERE id = #{musicId} AND favorite_count > 0")
    int decrementFavoriteCount(@Param("musicId") String musicId);

    /**
     * 增加评论次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET comment_count = comment_count + 1 WHERE id = #{musicId}")
    int incrementCommentCount(@Param("musicId") String musicId);

    /**
     * 减少评论次数
     *
     * @param musicId 音乐ID
     * @return 影响行数
     */
    @Update("UPDATE md_music SET comment_count = comment_count - 1 WHERE id = #{musicId} AND comment_count > 0")
    int decrementCommentCount(@Param("musicId") String musicId);
} 